package com.xwd.service.impl;

import com.xwd.dao.MenuDao;
import com.xwd.dao.impl.MenuDaoImpl;
import com.xwd.domain.Menu;
import com.xwd.service.MenuService;

import java.util.ArrayList;
import java.util.List;

public class MenuServiceImpl implements MenuService {
    MenuDao dao = new MenuDaoImpl();

    @Override
    public List<Menu> getMenuList() {
        List<Menu> menuList = dao.getMenuList();
        List<Menu> newMenuList = new ArrayList<>();
        for (Menu menu : menuList) {
            if(menu.getUpmenuId()==0){
                List<Menu> secondMenuList = new ArrayList<>();
                for (Menu menu1 : menuList) {
                    if(menu1.getUpmenuId()==menu.getMenuId()){
                        secondMenuList.add(menu1);
                    }
                }
                menu.setSecondMenu(secondMenuList);
                newMenuList.add(menu);
            }
        }
        return newMenuList;
    }

    @Override
    public List<Menu> getMenuListByRoleId(Integer roleId) {
        return dao.getMenuListByRoleId(roleId);
    }
}
